<template>
  <div>
    <el-form :model="form">
        {{form}}
        <el-form-item label="手机号" label-width="120px" :rules="[
      { required: true}]">
           <el-input v-model="form.phone"></el-input>
        </el-form-item>
        <el-form-item label="昵称" label-width="120px" :rules="[{ required: true}]">
          <el-input v-model="form.nickname"></el-input>
        </el-form-item>
        <el-form-item label="密码" label-width="120px">
          <el-input v-model="form.password"></el-input>
          <div>留空则不修改</div>
        </el-form-item>
        
        <el-form-item label="状态" label-width="120px">
          <el-switch v-model="form.status" :active-value="1" :inactive-value="2"></el-switch>
        </el-form-item>
        <el-form-item label-width="120px">
          <el-button type="primary" @click="commit">修改</el-button>
        </el-form-item>

      </el-form>
      
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import {reqmemberedit,reqmemberinfo} from '../../../http/api';
import { successAlert } from '../../../utils/alert';

export default {
  computed: {
    ...mapGetters({})
  },
  data() {
    return {
        form:{
        nikename: "",
        phone: "",
        password:"",
        status: 1
    }
    };
  },
  activated() {
    if(this.$route.path !== "/member/add"){
      // console.log(this.$route);
      reqmemberinfo({ uid:this.$route.params.id }).then((res) => {
            if (res.data.code === 200) {
                this.form = res.data.list;
                this.form.password = '';
            }
        }).catch((err) => {
            console.log('请求失败-----err:' + err);
        })
    }
  },
  beforeRouteLeave(to,from,next){
    // console.log(to,from);
    if(from.path !== '/member/add'){
        this.form = {
        nikename: "",
        phone: "",
        password:"",
        status: 1
    }
    };
    next()
    },
  
    methods: {
    ...mapActions({})
    ,
    commit(){
       reqmemberedit(this.form).then(res => {
        this.form.uid = this.$route.params.id;
        if(res.data.code===200){
          //弹成功
          successAlert(res.data.msg);
          //返回菜单管理
          this.$router.push('/member');
        }
      })
    }
    }
};
</script>
<style scoped lang="less">

</style>